/// @tags: SegmentTree RangeHistoryMax
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

constexpr int MAXN = 1e5 + 3, INF = 0x3f3f3f3f;

struct Node {
  int max, hismax, add, ass, maxadd, maxass;
  bool assed;
} tr[MAXN * 4];

inline void assmax(int &a, int b) {
  if (a < b) a = b;
}

inline void pushUp(int x) {
  tr[x].max = max(tr[x << 1].max, tr[x << 1 | 1].max);
  tr[x].hismax = max(tr[x << 1].hismax, tr[x << 1 | 1].hismax);
}

inline void pushAdd(int x, int val, int maxadd) {
  if (tr[x].assed) {
    assmax(tr[x].maxass, tr[x].ass + maxadd);
    assmax(tr[x].hismax, tr[x].max + maxadd);
    tr[x].max += val;
    tr[x].ass += val;
  } else {
    assmax(tr[x].maxadd, tr[x].add + maxadd);
    assmax(tr[x].hismax, tr[x].max + maxadd);
    tr[x].max += val;
    tr[x].add += val;
  }
}

inline void pushAss(int x, int val, int maxass) {
  if (tr[x].assed) {
    assmax(tr[x].maxass, maxass);
  } else {
    tr[x].assed = true;
    tr[x].maxass = maxass;
  }
  assmax(tr[x].hismax, maxass);
  tr[x].max = tr[x].ass = val;
}

inline void pushDown(int x) {
  pushAdd(x << 1, tr[x].add, tr[x].maxadd);
  pushAdd(x << 1 | 1, tr[x].add, tr[x].maxadd);
  tr[x].add = tr[x].maxadd = 0;
  if (tr[x].assed) {
    pushAss(x << 1, tr[x].ass, tr[x].maxass);
    pushAss(x << 1 | 1, tr[x].ass, tr[x].maxass);
    tr[x].assed = false;
    tr[x].ass = tr[x].maxass = 0;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    cin >> tr[x].max;
    tr[x].hismax = tr[x].max;
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushUp(x);
}

int queryMax(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x].max;
  pushDown(x);
  int mid = (l + r) >> 1, res = -INF;
  if (L <= mid) res = queryMax(x << 1, l, mid, L, R);
  if (mid < R) res = max(res, queryMax(x << 1 | 1, mid + 1, r, L, R));
  return res;
}

int queryHisMax(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x].hismax;
  pushDown(x);
  int mid = (l + r) >> 1, res = -INF;
  if (L <= mid) res = queryHisMax(x << 1, l, mid, L, R);
  if (mid < R) res = max(res, queryHisMax(x << 1 | 1, mid + 1, r, L, R));
  return res;
}

void add(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return pushAdd(x, v, v);
  pushDown(x);
  int mid = (l + r) >> 1;
  if (L <= mid) add(x << 1, l, mid, L, R, v);
  if (mid < R) add(x << 1 | 1, mid + 1, r, L, R, v);
  pushUp(x);
}

void assign(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return pushAss(x, v, v);
  pushDown(x);
  int mid = (l + r) >> 1;
  if (L <= mid) assign(x << 1, l, mid, L, R, v);
  if (mid < R) assign(x << 1 | 1, mid + 1, r, L, R, v);
  pushUp(x);
}

inline int main(void) {
  int t, e;
  cin >> t;
  build(1, 1, t);
  cin >> e;
  char opt;
  for (int x, y, z; e; --e) {
    cin >> opt >> x >> y;
    switch (opt) {
      case 'Q':
        cout << queryMax(1, 1, t, x, y) << '\n';
        break;
      case 'A':
        cout << queryHisMax(1, 1, t, x, y) << '\n';
        break;
      case 'P':
        cin >> z;
        add(1, 1, t, x, y, z);
        break;
      case 'C':
        cin >> z;
        assign(1, 1, t, x, y, z);
        break;
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4314 CPU监控.in", "r", stdin);
  freopen("P4314 CPU监控.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
